<template>
    <form class='form'>
        <slot></slot>
    </form>
</template>

<script>
    export default {
        provide() {
            return {
                form: this
            }
        },
        props: {
            model: {
                type: Object,
                required: true,
            },
            rules: Object
        },
        data() {
            return {
                fileds: []
            }
        },
        created() {
            // 挂载所有的 filed
            this.$on('formItemAdd', filed => this.fileds.push(filed));
        },
        methods: {
            async validate(fn) {
                const promiseList = this.fileds.map(formItem => formItem.validate())
                let resultList = await Promise.all(promiseList)
                let result = resultList.indexOf(false) === -1
                fn(result)
            }
        }
    }
</script>

<style lang="css" scoped>

</style>